<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>10.使用闭包获取区间商品</title>
</head>

<body>
  <script>
    let arr = [
        { name: "iphone", price: 12000 },
        { name: "imac", price: 25000 },
        { name: "ipad", price: 3600 }
      ];;
    // 筛选数据
    //let hd = arr.filter(function (v) {
    //  return v >= 2 && v<=9;
    //});
    // 使用闭包 特性
    function between (a, b) {
      return function (v) {
        //因为是子函数，根据闭包特性，可以访问父级别作用域
        return v.price >= a && v.price <= b;
      };
    }
    let hd = arr.filter(between(3500, 24000));

    console.log(hd);
  </script>
</body>

</html>